********************************************************************************
*MILITARY FATALITIES AND VOTING
********************************************************************************

clear 
set more off

	
*************************	
* ORGANIZING THE DATA   *
*************************

use "data/election_death_79_77.dta"


*Merge with data regarding 2 additional likud parties and add additional votes to rel_likud
drop _merge
merge m:1 lcode using "data/1969_vot_addition.dta"
replace rel_likud = likud2 if year == 1969

*Append 1965 voting data
append using "data/1965_vot.dta"
xtset lcode year

*Merge with data on munistatus
drop _merge
sort lcode 
merge m:1 lcode using "data/yeshuvim2016.dta" 
order _merge
sort _merge
*Note: 150 localities unknown municipal status seem small-regional council related places
drop _merge url lcode_name district religion

gen urban=1 if munistatus==0 | munistatus==99
replace urban=0 if munistatus!=0 & munistatus!=99

order lcode localityname year munistatus urban
sort lcode year
drop munistatus


gen casualties69=.
replace casualties69=death_count if year==1969
tempvar temp
bys lcode: egen `temp'=max(casualties69)
replace casualties69=`temp' if casualties69==.

gen casualties73=.
replace casualties73=death_count if year==1973
tempvar temp
bys lcode: egen `temp'=max(casualties73)
replace casualties73=`temp' if casualties73==.

gen casualties77=.
replace casualties77=death_count if year==1977
tempvar temp
bys lcode: egen `temp'=max(casualties77)
replace casualties77=`temp' if casualties77==.


gen  eligiblevoters69=.
replace eligiblevoters69=eligiblevoters if year==1969
tempvar temp
bys lcode: egen `temp'=max(eligiblevoters69)
replace eligiblevoters69=`temp' if eligiblevoters69==.

gen  eligiblevoters73=.
replace eligiblevoters73=eligiblevoters if year==1973
tempvar temp
bys lcode: egen `temp'=max(eligiblevoters73)
replace eligiblevoters73=`temp' if eligiblevoters73==.

gen  eligiblevoters77=.
replace eligiblevoters77=eligiblevoters if year==1977
tempvar temp
bys lcode: egen `temp'=max(eligiblevoters77)
replace eligiblevoters77=`temp' if eligiblevoters77==.

gen casualties69_pct=(casualties69/eligiblevoters69)*100
gen casualties73_pct=(casualties73/eligiblevoters73)*100
gen casualties77_pct=(casualties77/eligiblevoters77)*100

drop eligiblevoters69 eligiblevoters73 eligiblevoters77

replace eligiblevoters=eligiblevoters/1000
replace validvoters=validvoters/1000

foreach var in rel_dth rel_likud rel_emet rel_mafdal turnout{
replace `var'=`var'*100
}

*Define treatment period
gen PT=0
replace PT=1 if year>1969  //Yom Kippur onward as treatment period
	lab define PT 0 "Pre-YK war" 1 "Post-YK war", modify
	lab value PT PT
*Various treatment measures

gen TR=0
replace TR=1 if casualties73>0
replace TR=. if year! = 1965 & death_count==.
	lab define TR 0 "No 73' casualties" 1 "Casuaties in 73'"
	lab value TR TR

*add terror data
merge m:1 localityname year using "data/terror_vic.dta" 
replace terror_deaths = 0 if terror_deaths==.
drop if _merge ==2
*set data as panel
xtset lcode year
	


**Labeling variables
la var turnout "Turnout"
la var rel_likud "Likud vote-share"
la var rel_emet "Labor vote-share"
la var rel_mafdal "Mafdal vote-share"
la var death_count "# fallen soldiers"
la var casualties69 "# of fallen soldiers 1969"
la var casualties73 "# of fallen soldiers 1973"
la var casualties77 "# of fallen soldiers 1977"
la var rel_dth "% fallen soldiers"
la var casualties69_pct "% of fallen soldiers 1969"
la var casualties73_pct "% of fallen soldiers 1973"
la var casualties77_pct "% of fallen soldiers 1977"
la var eligiblevoters "Eligible voters, thousands"
la var validvoters "Valid voters, thousands"
la var urban "Urban locality"
la var PT "Post Yom Kipur war"
la var TR "73' casualties - binary"
la var terror_deaths "Terror Casualties"


*Generate Labor share in 1969 variable
gen labor_1969 = rel_emet if year == 1969
replace labor_1969 = labor_1969[_n-1] if year == 1973
replace labor_1969 = labor_1969[_n-1] if year == 1977



******************************	
***ANALYSIS -- TABLES A10-A15*
******************************


****TABLE A10: Military Casualties and Voting – Main Results

reg rel_likud TR##PT i.year if urban == 1, cl(lcode)

reg rel_likud TR##PT terror_deaths eligiblevoters i.year if urban == 1, cl(lcode)

reg rel_likud TR##PT terror_deaths eligiblevoters i.year if urban == 1 & year != 1977, cl(lcode)

reg rel_likud TR##PT terror_deaths eligiblevoters i.year if urban == 1 & year != 1973, cl(lcode)

reg rel_emet TR##PT i.year if urban == 1, cl(lcode)

reg rel_emet TR##PT terror_deaths eligiblevoters i.year if urban == 1, cl(lcode)

reg rel_emet TR##PT terror_deaths eligiblevoters i.year if urban == 1 & year != 1977, cl(lcode)

reg rel_emet TR##PT terror_deaths eligiblevoters i.year if urban == 1 & year != 1973, cl(lcode)


****TABLE A11: Casualties and Voting – Alternative Treatment Specification I
*75TH PERCENTILE OF % CASUALTIES =  .3787879

gen TR2=0
replace TR2=1 if casualties73>=9
replace TR2=. if year !=1965 & death_count==.
	lab define TR2 0 "$<$75$^{th}$ pctl 73' casualties" 1 "$>=$75$^{th}$ pctl casuaties in 73'"
	lab value TR2 TR2

reg rel_emet TR2##PT i.year if urban == 1, cl(lcode)

reg rel_likud TR2##PT terror_deaths eligiblevoters i.year if urban == 1, cl(lcode)

reg rel_likud TR2##PT i.year if urban == 1, cl(lcode)

reg rel_emet TR2##PT terror_deaths eligiblevoters i.year if urban == 1, cl(lcode)

****TABLE A12: Casualties and Voting – Alternative Treatment Specification II
* Deaths relative to eligible voters


gen eligible_vot73=.
replace eligible_vot73=eligiblevoters if year==1973
tempvar temp
bys lcode: egen `temp'=max(eligible_vot73)
replace eligible_vot73=`temp' if eligible_vot73==.

gen TR_pop=0
replace TR_pop = casualties73/eligible_vot73
replace TR_pop=. if year !=1965 & death_count==.


reg rel_likud c.TR_pop##PT i.year if urban == 1, cl(lcode)

reg rel_likud c.TR_pop##PT terror_deaths  i.year if urban == 1, cl(lcode)

reg rel_emet c.TR_pop##PT i.year if urban == 1, cl(lcode)

reg rel_emet c.TR_pop##PT terror_deaths i.year if urban == 1, cl(lcode)



* Merge deaths before and after the war collected from new MOD webpage
drop _merge
merge m:1 lcode using "data/halalim_for_rob.dta" 
replace before_war = 0 if before_war == .
replace after_war = 0 if after_war == .
gen casualties_since_YK = casualties73 - before_war
gen casualties_only_YK = casualties73 - (before_war + after_war)


*Various treatment measures

gen TR_since_YK=0
replace TR_since_YK=1 if casualties_since_YK>0
	lab define TR_since_YK 0 "No 73' casualties" 1 "Casuaties in 73'"
	lab value TR_since_YK TR_since_YK
	

gen TR_only_YK=0
replace TR_only_YK=1 if casualties_only_YK>0
	lab define TR_only_YK 0 "No 73' casualties" 1 "Casuaties in 73'"
	lab value TR_only_YK TR_only_YK	
	

****Table A13: Casualties and Voting – Alternative Treatment Specification Deaths Since YK War


reg rel_likud TR_since_YK##PT i.year if urban == 1, cl(lcode)

reg rel_likud TR_since_YK##PT terror_deaths eligiblevoters i.year if urban == 1, cl(lcode)

reg rel_emet TR_since_YK##PT i.year if urban == 1, cl(lcode)

reg rel_emet TR_since_YK##PT terror_deaths eligiblevoters i.year if urban == 1, cl(lcode)

reg turnout TR_since_YK##PT i.year if urban == 1, cl(lcode)

reg turnout TR_since_YK##PT terror_deaths eligiblevoters i.year if urban == 1, cl(lcode)


****Table A14: Casualties and Voting – Alternative Treatment Specification Deaths Only During YK War

reg rel_likud TR_only_YK##PT i.year if urban == 1, cl(lcode)

reg rel_likud TR_only_YK##PT terror_deaths eligiblevoters i.year if urban == 1, cl(lcode)

reg rel_emet TR_only_YK##PT i.year if urban == 1, cl(lcode)

reg rel_emet TR_only_YK##PT terror_deaths eligiblevoters i.year if urban == 1, cl(lcode)

reg turnout TR_only_YK##PT i.year if urban == 1, cl(lcode)

reg turnout TR_only_YK##PT terror_deaths eligiblevoters i.year if urban == 1, cl(lcode)



****Table A15: Casualties and Turnout

reg turnout TR##PT i.year if urban == 1, cl(lcode)

reg turnout TR##PT terror_deaths eligiblevoters i.year if urban == 1, cl(lcode)

reg turnout TR##PT terror_deaths eligiblevoters i.year if urban == 1 & year != 1977, cl(lcode)

reg turnout TR##PT terror_deaths eligiblevoters i.year if urban == 1 & year != 1973, cl(lcode)

